import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Index from '@/views/index.vue'


/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '医院后台管理新系统', icon: 'dashboard' }
    }]
  },

  {
    path: '/mt',
    component: Layout,
    redirect: '/mt/medic',
    name: 'mt',
    meta: { title: '医生管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'examine',
        name: 'examine',
        component: () => import('@/views/mt/medic/index'),
        meta: { title: '医生审核', icon: 'table' },

      },
      {
        path: 'serviceExamine',
        name: 'serviceExamine',
        component: () => import('@/views/mt/s_Examine/index'),
        meta: { title: '服务审核', icon: 'tree' }
      }
    ]
  },
  {
    path: '/usersManage',
    component: Layout,
    redirect: '/users/manage',
    name: 'users',
    meta: { title: '用户管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/u_list/index'),
        meta: { title: '用户列表', icon: 'user' }
      },
      {
        path: 'familyFile',
        name: 'familyFile',
        component: () => import('@/views/user/familyFile/index'),
        meta: { title: '家庭档案', icon: 'tree' }
      },
      {
        path: 'address',
        name: 'address',
        component: () => import('@/views/user/address/index'),
        meta: { title: '收货地址', icon: 'tree' }
      },

    ]
  },
  {
    path: '/prescription',
    component: Layout,
    redirect: '/prescription/manage',
    name: 'prescription',
    meta: { title: '处方管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'pList',
        name: 'pList',
        component: () => import('@/views/prescription/pList/index'),
        meta: { title: '处方列表', icon: 'tree' }
      },
      {
        path: 'pDetails',
        name: 'pDetails',
        component: () => import('@/views/index.vue'),
        meta: { title: '处方详情', icon: 'tree' }
      },

      {
        path: '/prescription/:id',// 动态路由  匹配到id后，进入到处方详情页面
        name: 'PrescriptionDetails',// 命名路由  命名为PrescriptionDetails
        component: () => import('@/views/prescription/pList/index') // 替换为实际的组件路径
      },
      // 其他路由...
    ]
  },
  {
    path: '/orderManage',
    component: Layout,
    redirect: '/order/manage',
    name: 'order',
    meta: { title: '订单管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'interrogation',
        name: 'interrogation',
        component: () => import('@/views/order/interrogation/index'),
        meta: { title: '问诊单管理', icon: 'tree' }
      },
      {
        path: 'register',
        name: 'register',
        component: () => import('@/views/order/register/index'),
        meta: { title: '挂号管理', icon: 'tree' }
      },
      {
        path: ' /order/:id',// 动态路由  匹配到id后，进入到订单详情页面
        name: 'OrderDetails',// 命名路由  命名为OrderDetails
        component: () => import('@/views/order/register/index') // 替换为实际的组件路径

      },

      {
        path: 'restoratives',
        name: 'restoratives',
        component: () => import('@/views/order/restoratives/index'),
        meta: { title: '药品订单管理', icon: 'tree' }
      },
      {
        path: 'details',
        name: 'details',
        hidden: true,
        component: () => import('@/views/order/details/index'),
        meta: { title: '订单详情', icon: 'tree' }
      },
      {
        path: 'prescriptionOrder',
        name: 'prescriptionOrder',
        component: () => import('@/views/order/prescriptionOrder/index'),
        meta: { title: '处方流转订单', icon: 'tree' }
      },
      {
        path: 'refundOrder',
        name: 'refundOrder',
        component: () => import('@/views/order/refundOrder/index'),
        meta: { title: '退款订单', icon: 'tree' },
      },
    ]
  },
  {
    path: '/productManage',
    component: Layout,
    redirect: '/product/manage',
    name: 'product',
    meta: { title: '商品管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'drugList',
        name: 'drugList',
        component: () => import('@/views/product/drugList/index'),
        meta: { title: '药品列表', icon: 'tree' }
      },
      {
        path: 'drugClassification',
        name: 'drugClassification',
        component: () => import('@/views/product/drugClassification/index'),
        meta: { title: '药品分类', icon: 'tree' }
      },
      {
        path: 'drugAudit',
        name: 'drugAudit',
        component: () => import('@/views/product/drugAudit/index'),
        meta: { title: '药品审核', icon: 'tree' }
      },
      {
        path: '/views/index',
        name: 'IndexView',
        component: () => import('@/views/index.vue'),
      },
    ]
  },
  {
    path:'/doctor',
    component: Layout,
    name: 'doctor',
    hidden: true,//隐藏当前菜单选项
    children: [
      {
        path: 'info/:doctorId',
        name: 'doctorinfo',
        component: () => import('@/views/mt/doctor/index'),
        meta: { title: '医生信息', icon: 'doctor' }
      }
      ]
  },




  // ----------------------------- 一下为原项目--------------------------------------
  {
    path: '/form',
    component: Layout,
    hidden: true,//隐藏当前菜单选项
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    hidden: true,//隐藏当前菜单选项
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    hidden: true,//隐藏当前菜单选项
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
